package com.tsd.jxc.stock.entity;

import com.alibaba.fastjson.JSON;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.utils.ListUtil;
import com.tsd.jxc.vo.PrintVo;
import com.tsd.system.entity.SysUserExt;
import io.swagger.annotations.ApiModel;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 出库单扩展
 *
 * @author Hillpool
 * @date 2022/07/29 15:06:33
 */
@ApiModel(description = "出库单扩展")
public class JxcStockOutbillExt extends JxcStockOutbill implements Serializable {

    /**
     * 执行状态 0-待执行
     */
    public static final int EXECUTE_STATE_WAIT = 0;
    /**
     * 执行状态 1-已执行
     */
    public static final int EXECUTE_STATE_EXECUTED = 1;
    /**
     * 出库类型 sale-销售出库
     */
    public static final String OUT_TYPE_SALE = "sale";
    /**
     * 出库类型 buy_return-采购退货出库
     */
    public static final String OUT_TYPE_BUY_RETURN = "buy_return";
    /**
     * 出库类型 allocation-调拨出库
     */
    public static final String OUT_TYPE_ALLOCATION = "allocation";

    /**
     * 审核状态 0-待审核
     */
    public static final int AUDIT_STATE_WAIT = 0;
    /**
     * 审核状态 1-审核通过
     */
    public static final int AUDIT_STATE = 1;
    /**
     * 审核状态 -1审核不通过
     */
    public static final int AUDIT_STATE_NO = -1;

    private String warehouse_name;

    private String goods_code;

    private String goods_name;

    private Integer goods_qty;

    private BigDecimal goods_price;

    private BigDecimal goods_amount;

    private String specifications;

    private String package_unit;

    private String client_code;

    private String client_name;

    private String client_short_name;

    private String client_display;
    //客户收货地址或者供应商收货地址
    private String client_recv_address;

    private String supplier_code;

    private String supplier_name;

    private String supplier_short_name;

    private String supplier_display;

    private List<JxcStockOutbillItemExt> item_list;

    private List<String> sid_list;

    public String getWarehouse_name() {
        return warehouse_name;
    }

    public void setWarehouse_name(String warehouse_name) {
        this.warehouse_name = warehouse_name;
    }

    public String getGoods_code() {
        return goods_code;
    }

    public void setGoods_code(String goods_code) {
        this.goods_code = goods_code;
    }

    public String getGoods_name() {
        return goods_name;
    }

    public void setGoods_name(String goods_name) {
        this.goods_name = goods_name;
    }

    public Integer getGoods_qty() {
        return goods_qty;
    }

    public void setGoods_qty(Integer goods_qty) {
        this.goods_qty = goods_qty;
    }

    public BigDecimal getGoods_price() {
        return goods_price;
    }

    public void setGoods_price(BigDecimal goods_price) {
        this.goods_price = goods_price;
    }

    public BigDecimal getGoods_amount() {
        return goods_amount;
    }

    public void setGoods_amount(BigDecimal goods_amount) {
        this.goods_amount = goods_amount;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications;
    }

    public String getPackage_unit() {
        return package_unit;
    }

    public void setPackage_unit(String package_unit) {
        this.package_unit = package_unit;
    }

    public String getClient_code() {
        return client_code;
    }

    public void setClient_code(String client_code) {
        this.client_code = client_code;
    }

    public String getClient_name() {
        return client_name;
    }

    public void setClient_name(String client_name) {
        this.client_name = client_name;
    }

    public String getClient_short_name() {
        return client_short_name;
    }

    public void setClient_short_name(String client_short_name) {
        this.client_short_name = client_short_name;
    }

    public String getClient_display() {
        return client_display;
    }

    public void setClient_display(String client_display) {
        this.client_display = client_display;
    }

    public String getSupplier_code() {
        return supplier_code;
    }

    public void setSupplier_code(String supplier_code) {
        this.supplier_code = supplier_code;
    }

    public String getSupplier_name() {
        return supplier_name;
    }

    public void setSupplier_name(String supplier_name) {
        this.supplier_name = supplier_name;
    }

    public String getSupplier_short_name() {
        return supplier_short_name;
    }

    public void setSupplier_short_name(String supplier_short_name) {
        this.supplier_short_name = supplier_short_name;
    }

    public String getSupplier_display() {
        return supplier_display;
    }

    public void setSupplier_display(String supplier_display) {
        this.supplier_display = supplier_display;
    }

    public List<JxcStockOutbillItemExt> getItem_list() {
        return item_list;
    }

    public void setItem_list(List<JxcStockOutbillItemExt> item_list) {
        this.item_list = item_list;
    }

    public List<String> getSid_list() {
        return sid_list;
    }

    public void setSid_list(List<String> sid_list) {
        this.sid_list = sid_list;
    }

    public String getSpec_name() {
        return null;
    }

    public PrintVo convert2Print(SysUserExt userExt) {
        PrintVo vo = new PrintVo();
        vo.setCreator_name(this.getCreator_name());
        vo.setCreate_date(this.getCreate_date());
        vo.setOut_type_name(this.getOut_type_name());
        vo.setCode(this.getCode());
        vo.setOut_date(this.getOut_date());
        vo.setSrc_code(this.getSrc_code());
        vo.setWarehouse_name(this.getWarehouse_name());
        vo.setOut_qty(this.getOut_qty());
        vo.setAudit_state(this.getAudit_state());
        vo.setAuditor_name(this.getAuditor_name());
        vo.setAudit_date(this.getAudit_date());
        vo.setExecute_state(this.getExecute_state());
        vo.setExecutor_name(this.getExecutor_name());
        vo.setExecute_date(this.getExecute_date());
        vo.setNote_info(this.getNote_info());
        vo.setClient_display(this.getClient_name());
        vo.setClient_recv_address(this.getClient_recv_address());
        List<PrintVo> itemList = ListUtil.map(this.getItem_list(), JxcStockOutbillItemExt::convert2Print);
        vo.setItem_list(itemList);
        vo.setDelivery_item_list(itemList);
        List<PrintVo> itemPositionList = new ArrayList<>();
        for (JxcStockOutbillItemExt itemExt : this.getItem_list()) {
//            List<PrintVo> voList = itemExt.convert2Print4Position(itemPositionList);
//            if (!HlpUtils.isEmptyList(voList)) {
//                itemPositionList.addAll(voList);
//            }
        }
        vo.setItem_position_list(itemPositionList);
        if (userExt != null) {
            vo.setPrint_name(userExt.getName());
        }
        vo.setPrint_datetime(new Date());
        return vo;
    }

    public String getExecute_state_name() {
        if (!HlpUtils.isEmpty(this.getExecute_state())) {
            if (this.getExecute_state() == EXECUTE_STATE_WAIT) {
                return "待执行";
            } else if (this.getExecute_state() == EXECUTE_STATE_EXECUTED) {
                return "已执行";
            }
        }
        return null;
    }

    public String getOut_type_name() {
        if (!HlpUtils.isEmpty(this.getOut_type())) {
            if (this.getOut_type().equalsIgnoreCase(OUT_TYPE_SALE)) {
                return "销售出库";
            } else if (this.getOut_type().equalsIgnoreCase(OUT_TYPE_BUY_RETURN)) {
                return "采购退货出库";
            } else if (this.getOut_type().equalsIgnoreCase(OUT_TYPE_ALLOCATION)) {
                return "调拨出库";
            }
        }
        return null;
    }

    public String getAudit_state_name() {
        if (!HlpUtils.isEmpty(this.getAudit_state())) {
            if (this.getAudit_state() == AUDIT_STATE_WAIT) {
                return "待审核";
            } else if (this.getAudit_state() == AUDIT_STATE) {
                return "审核通过";
            } else if (this.getAudit_state() == AUDIT_STATE_NO) {
                return "审核不通过";
            }
        }
        return null;
    }

    public String getClient_recv_address() {
        return client_recv_address;
    }

    public void setClient_recv_address(String client_recv_address) {
        this.client_recv_address = client_recv_address;
    }
}
